package com.xiaofeng.pochi.controller;

import com.xiaofeng.pochi.common.Result;
import com.xiaofeng.pochi.pojo.ShopUserAddress;
import com.xiaofeng.pochi.service.ShopUserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 *
 * @Author: chc
 * @Date: 2022/09/14/21:19
 * @Description:
 */
@RestController
@RequestMapping("/address")
public class ShopUserAddressController {

    @Autowired
    private ShopUserAddressService shopUserAddressService;

    /**
     * 添加地址
     * @param shopUserAddress
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result<?> save(@RequestBody ShopUserAddress shopUserAddress) {
        shopUserAddressService.save(shopUserAddress);
        return new Result<>("添加成功");
    }

    /**
     * 修改地址
     * @param shopUserAddress
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    public Result<?> update(@RequestBody ShopUserAddress shopUserAddress) {
        shopUserAddressService.update(shopUserAddress);
        return new Result<>("修改成功");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    public Result<?> delete(@PathVariable Long id) {
        shopUserAddressService.delete(id);
        return new Result<>("删除成功");
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    public Result<?> get(@PathVariable Long id) {
        ShopUserAddress shopUserAddress = shopUserAddressService.get(id);
        return new Result<>(shopUserAddress);
    }


    /**
     * 查询用户的收货地址列表
     * @return
     */
    @RequestMapping(value = "/getUserAddress", method = RequestMethod.GET)
    public Result<List<ShopUserAddress>> getUserAddress() {
        List<ShopUserAddress> list = shopUserAddressService.getUserAddress();
        return new Result<>(list);
    }

}
